package cz.muni.fi.pa165.sportclubmanager.dao;

import cz.muni.fi.pa165.sportclubmanager.entity.Player;
import cz.muni.fi.pa165.sportclubmanager.entity.PlayerOnRoster;
import cz.muni.fi.pa165.sportclubmanager.entity.Team;
import java.util.List;

/**
 * Provides basic CRUD operations with PlayerOnRoster entities.
 * Implementation is responsible for keeping data integrity, constrainted with:
 * <ol>
 * <li>each combination (team,player) is unique</li>
 * <li>each combination (team,number) is unique</li>
 * </ol>
 * In other words, a player can be present on a team's roster only once and all
 * players on one roster must have different numbers assigned.
 *
 * Any attemp to break the integrity will result in throwing
 * IllegalArgumentException.
 *
 * @author Matus Duchon (xduchon2@fi.muni.cz)
 */
public interface PlayerOnRosterDAO {

    /**
     * Creates new playerOnRoster relation, i.e. adds specified player to roster
     * of specified team.
     *
     * @param por wrapper for relation - all fields except id must be not null
     * @throws IllegalArgumentException when team or player field is null or has
     *                                  no id set
     *                                  or when data integrity would break
     */
    public void create(PlayerOnRoster por);

    /**
     * Updates playerOnRoster relation with new values.
     *
     * @param por wrapper for relation - all fields including id must be not
     *            null
     * @throws IllegalArgumentException when any field is null or has
     *                                  no id set
     *                                  or when data integrity would break
     */
    public void update(PlayerOnRoster por);

    /**
     * Removes playerOnRoster relation from data storage, i.e. removes player
     * from roster of specified team. Does nothing if there is no
     * such relation.
     *
     * @param por wrapper for relation with atleast id set
     * @throws IllegalArgumentException when por or por.id is null
     */
    public void remove(PlayerOnRoster por);

    /**
     * Returns relation object for given id.
     * 
     * @param id not-null id of existing relation
     * @return relation playerOnRoster with given id or null if no such exists
     * @throws IllegalArgumentException when id is null
     */
    public PlayerOnRoster find(Long id);

    /**
     * Returns list of all relations in data storage.
     *
     * @return list of playersOnRoster relations
     */
    public List<PlayerOnRoster> findAll();

    
    /**
     * Returns list of all relations in data storage with given team.
     *
     * @param team not-null team with id set
     * @return list of playersOnRoster relations with given team
     * @throws IllegalArgumentException when team or team.id is null
     */
    public List<PlayerOnRoster> findAllWithTeam(Team team);

    /**
     * Returns list of all relations in data storage with given player.
     *
     * @return list of playersOnRoster relations with given player
     * @throws IllegalArgumentException when player or player.id is null
     */
    public List<PlayerOnRoster> findAllWithPlayer(Player player);
}